#ifndef EPISODES_H
#define EPISODES_H
#include <QDateTime>
#include <QString>
#include <QUrl>
#include <QMetaType>

struct Subscription;

/** A downloadable podcast episode
*/
struct Episode {
    explicit Episode(Subscription* sub=0): subscription(sub) {}
    /** @return true if enough data members were set during parsing from rss item.
     */
    bool isComplete() const;
    /** @return where to put/find the episode */
    QString downloadPath() const;
    /** @return true if downloaded and playable */
    bool isAvailable() const ;

    QString name;
    QUrl downloadLink;
    QString description;
    QDateTime pubDate;
    Subscription* subscription;
};
Q_DECLARE_METATYPE(Episode)

inline bool operator==(const Episode& e1, const Episode& e2) {
    if (e1.downloadLink != e2.downloadLink) return false;
    if (e1.downloadPath() != e2.downloadPath()) return false;
    // do I care about the other fields?
    return true;
}
uint qHash(Episode);

/** A podcast subscription. */
struct Subscription {
    Subscription() : badDates(false) {}
    Subscription(QString directoryName, QUrl URL) :
        name(directoryName), url(URL), badDates(false) {}

    /** @return last time the rss was downloaded from net */
    QDateTime lastChecked() const;

    /** @return the location where downloads related to this subscription
            should be saved. Creates the directory if necessary. */
    QString downloadPath(QString fileName) const;

    QString name;
    QUrl url;
    bool badDates;
};

Q_DECLARE_METATYPE(Subscription)

/** @return a string that represents a datetime in terms of "ago" */
QString ago(QDateTime dt);

#endif // EPISODES_H
